package com.shuoyue.ycgk.ui.mine.order;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.Order;
import com.shuoyue.ycgk.entity.VipPrice;
import com.shuoyue.ycgk.entity.VipType;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.HashMap;
import java.util.List;

import io.reactivex.Observable;

public interface OrderContract {
    interface View extends BaseView {
        void setOrderList(List<Order> baseTypes);

    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getOrderList(Integer receiptStatus, Integer type) {
            apply(model.getOrderList(receiptStatus, type))
                    .subscribe(new ApiSubscriber<Optional<List<Order>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<Order>> listOptional) {
                            super.onNext(listOptional);
                            mView.setOrderList(listOptional.getIncludeNull());
                        }
                    });
        }


        public void getOrderInfo(int id) {
            apply(model.getOrderInfo(id))
                    .subscribe(new ApiSubscriber<Optional<List<Order>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<Order>> listOptional) {
                            super.onNext(listOptional);
                            mView.setOrderList(listOptional.getIncludeNull());
                        }
                    });
        }
    }

    class Model extends BaseModel {
        Observable<BaseResult<List<Order>>> getOrderList(Integer receiptStatus, Integer type) {
            return RetrofitClient.getInstance().getApi().getOrderList(receiptStatus, type);
        }

        Observable<BaseResult<List<Order>>> getOrderInfo(int id) {
            return RetrofitClient.getInstance().getApi().getOrderInfo(id);
        }

    }
}
